const app = getApp()
import Common from '../../../common/common.js';
let common = new Common;
Page({ 
  data: {
    isEnd: false, //是否到底
    page:1,
    problemFeedbackList:[]
  }, 
  onLoad: function (options) {

  },  
  // 图片点击放大 
  previewImg: function (e) {
    let idsStr = e.currentTarget.dataset.effect_pic.map(function(obj,index){
        return obj.picUrl;
    }).join(",");
    let a = idsStr.split(','); 
    let src = e.currentTarget.dataset.src;//获取data-src  循环单个图片链接
    let imgList = a;//获取data-effect_pic   图片列表
    //图片预览
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  },
  onShow: function () { 
    if(this.data.back == 1){ // 下一页定义赋值
      this.setData({
        problemFeedbackList:[], 
      })
    }
    this.setData({ 
      page:1,
      back:0, //进入页面重新赋值
    }) 
    this.feedbackList(1) //反馈列表刷新
  },  
  // 反馈列表刷新
  feedbackList(type) {
    wx.showLoading({
      title: '加载中',
    }) 
    let data = {
      condition: {
        orgSeq: app.globalData.orgSeq,  
      },
      current: this.data.page,
      size: 10,
    } 
    common.requestAjax('/api/user-service/v1/feedback/queryFeedback', 'POST', data).then(res => {
      if (res.data.code==1) {
        wx.hideLoading()  
        let list = this.data.problemFeedbackList || [];
        let isEnd = this.data.isEnd; 
        if (type == 1) {
          //下拉刷新
          list = res.data.records;
          isEnd = false;
        } else if (type == 2) { 
          list = list.concat(res.data.records); 
          if (res.data.records.length == 0) { 
            isEnd = true;//最后一行没数据 到底了
          } 
        }
        this.setData({
          problemFeedbackList: list,
          isEnd,
        })
      }else{
        common.showToast(res.data.message)
      }
    }).catch(err => {
      console.log(err);
    })
  },
  // 跳转详情页
  workOrderDetalil:function(e){ 
    let showModular = e.currentTarget.dataset.showmodular
    let uuid  = e.currentTarget.dataset.uuid
    wx.navigateTo({
      url: '/pages/myCenter/workOrderDetail/workOrderDetail?showModular='+showModular+'&uuid='+uuid,
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // if (!this.data.isEnd) {
      this.setData({
        page: Number(this.data.page) + 1
      })
      this.feedbackList(2)
      wx.showLoading({
        title: '正在加载中...',
      })
    // }
  }, 
  /**
 * 页面相关事件处理函数--监听用户下拉动作
 */
  onPullDownRefresh: function () {

  },
})